//
//  MainViewController.swift
//  新浪微博
//
//  Created by mac on 15/11/26.
//  Copyright © 2015年 mac. All rights reserved.
// 

import UIKit

class MainViewController: UITabBarController {

    let mainTabBar = MainTabBar()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //将系统的tabbar 替换为maintabbar就完成自定义
        //系统的tabbar是只读属性,不能够直接操作
       
        //通过kvc机制,动态的修改tabbar的身份
        setValue(mainTabBar, forKey: "tabBar")
        
        mainTabBar.composeBtn .addTarget(self, action: "composeBtnClick", forControlEvents: .TouchUpInside)
        
        
        addChildViewControllers(HomeViewController(),title: "首页",imageName: "tabbar_home")
        addChildViewControllers(MessageViewController(),title: "消息",imageName: "tabbar_message_center")
        addChildViewControllers(DiscoverViewController(),title: "发现",imageName: "tabbar_discover")
        addChildViewControllers(ProfiledViewController(),title: "我",imageName: "tabbar_profile")
    }
    //target action 机制,直接使用oc
    //为了让swift中的与发能有兼容oc方法选择器,需要使用@objc
    @objc private func composeBtnClick(){
    print(__FUNCTION__)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    //private私有方法,只能在当前内的内部使用
    private func addChildViewControllers(viewController: UIViewController, title: String ,imageName: String) {
        viewController.title = title
        viewController.tabBarItem.image = UIImage(named: imageName)
        self.tabBar.tintColor = UIColor.orangeColor()
        //添加到nav控制器中
        let nav = UINavigationController(rootViewController: viewController)
        //添加到tabbar中
        addChildViewController(nav)
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
